#import "WFFarmCrop.h"

@implementation WFFarmCrop

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    return [self yy_modelInitWithCoder:aDecoder];
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    return [self yy_modelEncodeWithCoder:aCoder];
}

+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{
             @"phaseId" : @[@"phaseId", @"time.timeId"],
             @"phaseName" : @[@"phaseName", @"time.timeName"],
             };
}

@end

@implementation NSArray (WFFarmCrop)

- (NSString *)cropIdComponentsJoinedByString:(NSString *)separator {
    NSMutableArray *arr = [NSMutableArray array];
    for (WFFarmCrop *crop in self) {
        if (![crop isKindOfClass:[WFFarmCrop class]]) {
            continue;
        }
        NSString *str = [NSString stringWithFormat:@"%@.%@", crop.cropId, crop.phaseId];
        [arr addObject:str];
    }
    return [arr componentsJoinedByString:separator];
}

- (NSString *)cropNameComponentsJoinedByString:(NSString *)separator {
    NSMutableArray *arr = [NSMutableArray array];
    for (WFFarmCrop *crop in self) {
        if (![crop isKindOfClass:[WFFarmCrop class]]) {
            continue;
        }
        NSString *str = [NSString stringWithFormat:@"%@/%@", crop.cropName, crop.phaseName];
        [arr addObject:str];
    }
    return [arr componentsJoinedByString:separator];
}


@end
